﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class TotalPlan_ModifyTotalPlan : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            bind();
        }
    }

    void bind()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsInt("TotalPlanId");
        TotalPlanMgr dllTotalPlanMgr = new TotalPlanMgr();

        DataTable dt = dllTotalPlanMgr.get(TotalPlanMgr.field.TotalPlanId.ToString(), _value);
        if (dt.Rows.Count > 0)
        {
            #region 去除标记
            dt.Rows[0]["MasterDepartment"] = dt.Rows[0]["MasterDepartment"].ToString().Replace("&", "");
            dt.Rows[0]["MasterDepartment"] = dt.Rows[0]["MasterDepartment"].ToString().Replace("nbsp;", "");
            dt.Rows[0]["MasterDepartment"] = dt.Rows[0]["MasterDepartment"].ToString().Replace("amp;", "");
            dt.Rows[0]["CompleteTime"] = dt.Rows[0]["CompleteTime"].ToString().Replace("&", "");
            dt.Rows[0]["CompleteTime"] = dt.Rows[0]["CompleteTime"].ToString().Replace("nbsp;", "");
            dt.Rows[0]["CompleteTime"] = dt.Rows[0]["CompleteTime"].ToString().Replace("amp;", "");
            dt.Rows[0]["MasterPeople"] = dt.Rows[0]["MasterPeople"].ToString().Replace("&", "");
            dt.Rows[0]["MasterPeople"] = dt.Rows[0]["MasterPeople"].ToString().Replace("nbsp;", "");
            dt.Rows[0]["MasterPeople"] = dt.Rows[0]["MasterPeople"].ToString().Replace("amp;", "");
            dt.Rows[0]["TotalPlanSortId"] = dt.Rows[0]["TotalPlanSortId"].ToString().Replace("&", "");
            dt.Rows[0]["TotalPlanSortId"] = dt.Rows[0]["TotalPlanSortId"].ToString().Replace("nbsp;", "");
            dt.Rows[0]["TotalPlanSortId"] = dt.Rows[0]["TotalPlanSortId"].ToString().Replace("amp;", "");
            dt.Rows[0]["WorkItem"] = dt.Rows[0]["WorkItem"].ToString().Replace("&", "");
            dt.Rows[0]["WorkItem"] = dt.Rows[0]["WorkItem"].ToString().Replace("nbsp;", "");
            dt.Rows[0]["WorkItem"] = dt.Rows[0]["WorkItem"].ToString().Replace("amp;", "");
            dt.Rows[0]["WorkItemAdditional"] = dt.Rows[0]["WorkItemAdditional"].ToString().Replace("&", "");
            dt.Rows[0]["WorkItemAdditional"] = dt.Rows[0]["WorkItemAdditional"].ToString().Replace("nbsp;", "");
            dt.Rows[0]["WorkItemAdditional"] = dt.Rows[0]["WorkItemAdditional"].ToString().Replace("amp;", "");
            #endregion
            this.txtCompleteTime.Text = Convert.ToDateTime(dt.Rows[0]["CompleteTime"].ToString()).ToShortDateString();
            this.txtMasterDepartment.Text = dt.Rows[0]["MasterDepartment"].ToString();
            this.txtMasterPeople.Value = dt.Rows[0]["MasterPeople"].ToString();
            this.txtTotalPlanSortId.Value = dt.Rows[0]["TotalPlanSortId"].ToString();
            if (dt.Rows[0]["Source"].ToString() == "新增")
            {
                this.txtWorkItem.Text = dt.Rows[0]["WorkItemAdditional"].ToString();
                this.lblWorkItem.Text = dt.Rows[0]["WorkItem"].ToString(); ;
            }
            else
            {
                this.txtWorkItem.Text = dt.Rows[0]["WorkItemAdditional"].ToString();
            }            
        }
    }


    /// <summary>
    /// 判断控件值是否为空
    /// </summary>
    /// <returns>空返回0，有值返回1</returns>
    /// <author>gzz</author>
    /// <date>2009-3-19 </date>
    int isNull()
    {
        #region 验证是否为空
        if (this.txtTotalPlanSortId.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtMasterDepartment.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return 0;
        }
        
        return 1;
        #endregion
    }


    /// <summary>
    /// 修改事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        int _isnull = isNull();
        if (_isnull == 0)
        {
            Utility.HttpHelp.alert("请输入完整", Page);
            return;
        }
        else
        {
            if (this.txtMasterPeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("责任人不可为多人！", Page);
                return;
            }
            object[] _value = new object[6];
            _value[0] = Utility.HttpHelp.getParamsInt("TotalPlanId");
            _value[1] =Convert.ToDateTime(this.txtCompleteTime.Text);
            _value[2] = this.txtMasterDepartment.Text;
            _value[3] = this.txtMasterPeople.Value;
            _value[4] = this.txtTotalPlanSortId.Value;
            _value[5] = this.txtWorkItem.Text;
            TotalPlanMgr dllTotalPlanMgr = new TotalPlanMgr();
            int result = dllTotalPlanMgr.edit(TotalPlanMgr.field.TotalPlanId.ToString(), _value);
            if (result == 0)
            {
                Utility.HttpHelp.alert("修改总表计划未成功，请重试！", Page);
            }
            else
            {
                string department = Server.UrlDecode(Utility.HttpHelp.getParamsString("department"));
                string Year = Utility.HttpHelp.getParamsString("Year");
                //Utility.HttpHelp.closeWindow("DraftTotalPlan.aspx?department="+department+"&Year="+Year, Page);
                Utility.HttpHelp.closeWindowRefresh(Page);
            }
        }
    }
}
